package org.opens.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.opens.dao.ShiroUserDao;
import org.opens.entity.ShiroUser;
import org.opens.service.ShiroUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ShiroUserServiceImpl implements ShiroUserService {

    @Autowired
    private ShiroUserDao shiroUserDao;

    @Override
    public IPage<ShiroUser> page(int pageNumber, int pageSize, ShiroUser param) {
        Page<ShiroUser> page = new Page<>(pageNumber, pageSize);
        if (StrUtil.isNotBlank(param.getName())) {
            String nameTmp1 = StrUtil.addPrefixIfNot(param.getName(), "%");
            String nameTmp2 = StrUtil.addSuffixIfNot(nameTmp1, "%");
            param.setName(nameTmp2);
        }
        return shiroUserDao.queryPage(page, param);
    }
}
